Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Collections.​Generic.​Dictionary<​TKey, TValue>
Assembly: System.Collections
Inheritance: object → Dictionary
Implemented Interfaces
- IDictionary`2 (Inherits: ICollection<​KeyValuePair<​TKey, TValue>>IEnumerable<​KeyValuePair<​TKey, TValue>>IEnumerable)
- IReadOnlyDictionary`2 (Inherits: IEnumerable<​KeyValuePair<​TKey, TValue>>IEnumerableIReadOnlyCollection<​KeyValuePair<​TKey, TValue>>)
- IDictionary (Inherits: ICollectionIEnumerable)
- Runtime.​Serialization.​IDeserializationCallback
- Runtime.​Serialization.​ISerializable
Represents a collection of keys and values.
Properties
public
IEqualityComparer<​TKey>
Comparer
Gets the <see cref="T:System.Collections.Generic.IEqualityComparer`1" /> that is used to determine equality of keys for the dictionary.
public
int
Count
Gets the number of key/value pairs contained in the <see cref="T:System.Collections.Generic.Dictionary`2" /> .
public
int
Capacity
Gets the total numbers of elements the internal data structure can hold without resizing.
public
TValue
Item
public
KeyCollection<​TKey, TValue>
Keys
Gets a collection containing the keys in the <see cref="T:System.Collections.Generic.Dictionary`2" /> .
public
ValueCollection<​TKey, TValue>
Values
Gets a collection containing the values in the <see cref="T:System.Collections.Generic.Dictionary`2" /> .
Methods
public
void
Add​(TKey key,
TValue value)
Adds the specified key and value to the dictionary.
key
The key of the element to add.
value
The value of the element to add. The value can be <see langword="null" /> for reference types.
public
void
Clear​()
Removes all keys and values from the <see cref="T:System.Collections.Generic.Dictionary`2" /> .
public
bool
ContainsKey​(TKey key)
Determines whether the <see cref="T:System.Collections.Generic.Dictionary`2" /> contains the specified key.
Returns <see langword="true" /> if the <see cref="T:System.Collections.Generic.Dictionary`2" /> contains an element with the specified key; otherwise, <see langword="false" /> .
key
The key to locate in the <see cref="T:System.Collections.Generic.Dictionary`2" /> .
public
bool
ContainsValue​(TValue value)
Determines whether the <see cref="T:System.Collections.Generic.Dictionary`2" /> contains a specific value.
Returns <see langword="true" /> if the <see cref="T:System.Collections.Generic.Dictionary`2" /> contains an element with the specified value; otherwise, <see langword="false" /> .
value
The value to locate in the <see cref="T:System.Collections.Generic.Dictionary`2" /> . The value can be <see langword="null" /> for reference types.
public
int
EnsureCapacity​(int capacity)
Ensures that the dictionary can hold up to a specified number of entries without any further expansion of its backing storage.
Returns The current capacity of the <see cref="T:System.Collections.Generic.Dictionary`2" /> .
capacity
The number of entries.
public
AlternateLookup<​TKey, TValue, TAlternateKey>
GetAlternateLookup​()
Gets an instance of a type that can be used to perform operations on the current <see cref="T:System.Collections.Generic.Dictionary`2" /> using a <typeparamref name="TAlternateKey" /> as a key instead of a <typeparamref name="TKey" /> .
Returns The created lookup instance.
public
Enumerator<​TKey, TValue>
GetEnumerator​()
Returns an enumerator that iterates through the <see cref="T:System.Collections.Generic.Dictionary`2" /> .
Returns A <see cref="T:System.Collections.Generic.Dictionary`2.Enumerator" /> structure for the <see cref="T:System.Collections.Generic.Dictionary`2" /> .
public
void
GetObjectData​(Runtime.​Serialization.​SerializationInfo info,
Runtime.​Serialization.​StreamingContext context)
Implements the <see cref="T:System.Runtime.Serialization.ISerializable" /> interface and returns the data needed to serialize the <see cref="T:System.Collections.Generic.Dictionary`2" /> instance.
info
A <see cref="T:System.Runtime.Serialization.SerializationInfo" /> object that contains the information required to serialize the <see cref="T:System.Collections.Generic.Dictionary`2" /> instance.
context
A <see cref="T:System.Runtime.Serialization.StreamingContext" /> structure that contains the source and destination of the serialized stream associated with the <see cref="T:System.Collections.Generic.Dictionary`2" /> instance.
public
void
OnDeserialization​(object sender)
Implements the <see cref="T:System.Runtime.Serialization.ISerializable" /> interface and raises the deserialization event when the deserialization is complete.
sender
The source of the deserialization event.
public
bool
Remove​(TKey key)
Removes the value with the specified key from the <see cref="T:System.Collections.Generic.Dictionary`2" /> .
Returns <see langword="true" /> if the element is successfully found and removed; otherwise, <see langword="false" /> . This method returns <see langword="false" /> if <paramref name="key" /> is not found in the <see cref="T:System.Collections.Generic.Dictionary`2" /> .
key
The key of the element to remove.
public
void
TrimExcess​()
Sets the capacity of this dictionary to what it would be if it had been originally initialized with all its entries.
public
void
TrimExcess​(int capacity)
Sets the capacity of this dictionary to hold up a specified number of entries without any further expansion of its backing storage.
capacity
The new capacity.
public
bool
TryAdd​(TKey key,
TValue value)
Attempts to add the specified key and value to the dictionary.
Returns <see langword="true" /> if the key/value pair was added to the dictionary successfully; otherwise, <see langword="false" /> .
key
The key of the element to add.
value
The value of the element to add. It can be <see langword="null" /> .
public
bool
Equals​(object obj)
Inherited from object
protected
void
Finalize​()
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object
public
string
ToString​()
Inherited from object